package org.example

import org.apache.spark.sql.SQLContext
import org.apache.spark.{SparkConf, SparkContext}

object SqlTest {

  //同义灵码    idea 2021  +

  // 样例类  它具有 getter 和 setter 的 方法  ===》 相当于是 java bean 类
  case class Person(name:String,age:Int,height:Int)
  def main(args: Array[String]): Unit = {


    val conf = new SparkConf().setMaster("local[*]").setAppName("helloSparkSQL")
    val sc = new SparkContext(conf)

    sc.setLogLevel("error")

    val person = Array( Person("xaioli",18,170)    , Person("xiaowang",19,183),Person("xiaoming",20,185)   )

    val personRDD = sc.parallelize(person)

    val sqlCon = new SQLContext(sc)
    import sqlCon.implicits._
    personRDD.toDF().show()

    val df = personRDD.toDF()
    df.registerTempTable("person")
    sqlCon.sql("select name from person ").show()

    sqlCon.sql("select name from person where age > 18").show()

















































  }









}

